<?php

namespace AppVue;

use Illuminate\Foundation\Application;

/**
 * Created by PhpStorm.
 * User: YongXuan.Huang
 * Date: 2017/4/18
 * Time: 14:25
 */
class LaravelVueApplication extends Application
{
    public function path($path = '')
    {
        return __DIR__ . ($path ? DIRECTORY_SEPARATOR . $path : $path);
    }

    public function basePath($path = '') {
        return $this->getAppPath($path);
    }

    public function resourcePath($path = '')
    {
        return $this->getWebPath() . ($path ? DIRECTORY_SEPARATOR . $path : $path);
    }

    public function storagePath()
    {
        return $this->getAppPath('var');
    }

    public function publicPath()
    {
        return $this->getAppPath('public');
    }

    public function configPath($path = '')
    {
        return $this->getResourcePath() . DIRECTORY_SEPARATOR . 'config' . ($path ? DIRECTORY_SEPARATOR . $path : $path);
    }

    public function bootstrapPath($path = '')
    {
        return $this->getResourcePath() . DIRECTORY_SEPARATOR . 'bootstrap' . ($path ? DIRECTORY_SEPARATOR . $path : $path);
    }

    public function databasePath($path = '')
    {
        return $this->getResourcePath() . DIRECTORY_SEPARATOR . 'database' . ($path ? DIRECTORY_SEPARATOR . $path : $path);
    }

    public function getCachedServicesPath()
    {
        $path = $this->storagePath() . DIRECTORY_SEPARATOR . 'framework' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR . 'services.php';
        return $path;
    }

    public function environmentPath()
    {
        return $this->getAppPath();
    }

    private function getResourcePath()
    {
        return realpath(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'resources');
    }

    private function getWebPath()
    {
        return realpath(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'web');
    }

    private function getPhpPath()
    {
        return realpath(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'php');
    }

    private function getAppPath($dir = '')
    {
        return realpath(__DIR__ . DIRECTORY_SEPARATOR
            . '..'
            . DIRECTORY_SEPARATOR
            . '..'
            . DIRECTORY_SEPARATOR
            . '..'
            . DIRECTORY_SEPARATOR
            . DIRECTORY_SEPARATOR
            . $dir
        );
    }
}